package com.infore.airsupervise.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.infore.airsupervise.R;
import com.infore.airsupervise.bean.StationGridE;

import java.util.List;

/**
 * @features:
 * @author: WuTao
 * @date: 2017/4/17 16:47
 */
public class SpinnerGridAdapter  extends BaseAdapter {
    private List<StationGridE> gridEList ;
    private Context context;

    public SpinnerGridAdapter(Context context, List<StationGridE> gridEList) {
        this.context = context;
        this.gridEList = gridEList;
    }

    @Override
    public int getCount() {
        return null == gridEList ? 0: gridEList.size()+1;
    }

    @Override
    public Object getItem(int i) {
        return  i == 0 ? new StationGridE() : gridEList.get(i-1);
    }

    @Override
    public long getItemId(int i) {
        return   i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if(view == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_spinner_grid,viewGroup,false);
        }
        TextView tv = (TextView) view.findViewById(R.id.tv_spinner);
        if (i != 0) {
           StationGridE gridE = gridEList.get(i-1);
            tv.setText(gridE.getName());
        } else {
            tv.setText("未选择");
        }
        return view;
    }
}
